//
//  BaseNavViewController.swift
//  Weibo
//
//  Created by 张小东 on 16/1/20.
//  Copyright © 2016年 Mr.Zhang. All rights reserved.
//

import UIKit

class BaseNavViewController: UINavigationController ,UIGestureRecognizerDelegate{

    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 重新设置返回手势的代理
        
        
        self.interactivePopGestureRecognizer?.delegate = self
        

        // Do any additional setup after loading the view.
    }

    override func pushViewController(viewController: UIViewController, animated: Bool) {
        // 调用super的方法
        // 设置底部tabBar隐藏
        if childViewControllers.count != 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            let btn = UIButton(title: "返回", fontSize: 14, color: UIColor.darkGrayColor(), backImageName: nil,imageName:"navigationbar_back_withtext")
            
            btn.addTarget(self, action: "back", forControlEvents: .TouchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        }
        
        // 这一句代码执行完毕后才会真正的添加到导航视图控制器中成为子视图
        super.pushViewController(viewController, animated: animated)
        
    }
    
    @objc private func back() {
        // 在本类中 self就是导航控制器
        popViewControllerAnimated(true)
        
        
    }
    
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
//        if childViewControllers.count > 0 {
//            return true
//        }
//        return false
//        
        return childViewControllers.count > 1
    }
    
    
    
}
